home *** CD-ROM | disk | FTP | other *** search
/ Enigma Amiga Life 109 / EnigmaAmiga109CD.iso / dalla rivista / host contacted / jikes.lha / jikes-1.11 / src / diagnose.h < prev    next >
C/C++ Source or Header  |  1999-11-03  |  5KB  |  164 lines

  1. // $Id: diagnose.h,v 1.6 1999/11/03 00:46:30 shields Exp $
  2. //
  3. // This software is subject to the terms of the IBM Jikes Compiler
  4. // License Agreement available at the following URL:
  5. // http://www.ibm.com/research/jikes.
  6. // Copyright (C) 1996, 1998, International Business Machines Corporation
  7. // and others.  All Rights Reserved.
  8. // You must accept the terms of that agreement to use this software.
  9. //
  10. #ifndef diagnose_INCLUDED
  11. #define diagnose_INCLUDED
  12.  
  13. #include "config.h"
  14. #include "parser.h"
  15.  
  16. struct PrimaryRepairInfo
  17. {
  18.     int code,
  19.         distance,
  20.         buffer_position,
  21.         misspell_index,
  22.         symbol;
  23. };
  24.  
  25. struct RepairCandidate
  26. {
  27.     int symbol;
  28.     Location location;
  29. };
  30.  
  31. struct StateInfo
  32. {
  33.     int state,
  34.         next;
  35. };
  36.  
  37.  
  38. class ParseError : public javaprs_table
  39. {
  40. public:
  41.     void Report(int msg_level, int msg_code, int name_index,
  42.                 LexStream::TokenIndex left_token, LexStream::TokenIndex right_token,
  43.                 int scope_name_index = 0);
  44.  
  45.     void SortMessages();
  46.  
  47.     ParseError(Control &control_, LexStream *lex_stream_) : control(control_),
  48.                                                             lex_stream(lex_stream_),
  49.                                                             errors(256)
  50.     {}
  51.     void PrintMessages();
  52.  
  53. private:
  54.  
  55.     Control &control;
  56.     LexStream *lex_stream;
  57.  
  58.     struct ErrorInfo
  59.     {
  60.         LexStream::TokenIndex left_token,
  61.                               right_token;
  62.         int                   name_index;
  63.         int                   right_string_length;
  64.         int                   num;
  65.         unsigned char         msg_level;
  66.         unsigned char         msg_code;
  67.         unsigned              scope_name_index;
  68.     };
  69.  
  70.     Tuple<ErrorInfo> errors;
  71.  
  72.     void PrintLargeMessage(int k);
  73.     void PrintMessage(int k);
  74.     void PrintPrimaryMessage(int k);
  75.     void PrintSecondaryMessage(int k);
  76. };
  77.  
  78.  
  79. class DiagnoseParser : public Parser
  80. {
  81. public:
  82.  
  83.     DiagnoseParser(Control &control_, LexStream *lex_stream_) : next_stack(NULL),
  84.                                                                 prev_stack(NULL),
  85.                                                                 scope_index(NULL),
  86.                                                                 scope_position(NULL),
  87.                                                                 state_pool(256),
  88.                                                                 error(control_, lex_stream_)
  89.     {
  90.         lex_stream = lex_stream_;
  91.         memset(list, 0, NUM_SYMBOLS * sizeof(int));
  92.         DiagnoseParse();
  93.  
  94.         return;
  95.     }
  96.  
  97.     ~DiagnoseParser()
  98.     {
  99.         delete [] next_stack;
  100.         delete [] prev_stack;
  101.         delete [] scope_index;
  102.         delete [] scope_position;
  103.     }
  104.  
  105. private:
  106.  
  107.     int next_stack_top,
  108.         *next_stack,
  109.  
  110.         prev_stack_top,
  111.         *prev_stack,
  112.  
  113.         scope_stack_top,
  114.         *scope_index,
  115.         *scope_position;
  116.  
  117.     int list[NUM_SYMBOLS + 1];
  118.  
  119.     enum { NIL = -1 };
  120.     Tuple<StateInfo> state_pool;
  121.     int *state_seen; // this variable is managed entirely by the function "scope_trial"
  122.  
  123.     ParseError error;
  124.  
  125.     void DiagnoseParse();
  126.  
  127.     void ReallocateStacks();
  128.  
  129.     RepairCandidate ErrorRecovery(TokenObject error_token);
  130.     RepairCandidate PrimaryPhase(TokenObject error_token);
  131.     bool MergeCandidate(int state, int buffer_position);
  132.     PrimaryRepairInfo CheckPrimaryDistance(int stack[],
  133.                                            int stack_top,
  134.                                            PrimaryRepairInfo repair);
  135.     RepairCandidate PrimaryDiagnosis(PrimaryRepairInfo repair);
  136.     int GetTermIndex(int stack[], int stack_top,
  137.                      int tok, int buffer_position);
  138.     int GetNtermIndex(int start, int sym, int buffer_position);
  139.     int Misspell(int sym, TokenObject tok);
  140.     RepairCandidate SecondaryPhase(TokenObject error_token);
  141.     SecondaryRepairInfo MisplacementRecovery
  142.              (int stack[],
  143.               int stack_top,
  144.               int last_index,
  145.               SecondaryRepairInfo misplaced, bool stack_flag);
  146.     SecondaryRepairInfo SecondaryRecovery
  147.              (int stack[],
  148.               int stack_top,
  149.               int last_index,
  150.               SecondaryRepairInfo repair, bool stack_flag);
  151.     void SecondaryDiagnosis(SecondaryRepairInfo repair);
  152.  
  153.     void RepairParse(TokenObject);
  154.  
  155.     PrimaryRepairInfo ScopeTrial(int stack[], int stack_top,
  156.                                  PrimaryRepairInfo repair);
  157.     void ScopeTrialCheck(int stack[], int stack_top,
  158.                          PrimaryRepairInfo& repair, int indx);
  159.     bool SecondaryCheck(int stack[], int stack_top,
  160.                         int buffer_position, int distance);
  161. };
  162.  
  163. #endif
  164.